import request from '@/utils/request'
import type { Response } from '@/utils/type'
import type { AxiosResponse } from 'axios/index'
import axios from 'axios'

export interface CommunityInfoResp {
  communityActivitySpaceInfo: any
  communityBaseInfo: any
  communityFeaturedFacilitiesInfo: any
  communityGovernanceInfo: any
  communityPublicServiceInfo: any
  communitySupportingFacilitiesInfo: any
}

export interface CheckRecordResp {
  applyCause?: string
  applyStatus: number
  applyText: string
  applyTime: string
  applyUserId: string
  areaName: string
  pkid: string
  remark?: string
  resourceId: string
  userName: string
}

/**
 * 查询指定层级未填报社区数量
 */
export const unsavedCount = (
  params: object = {}
): Promise<Response<number>> => {
  return request('/proposal/community/base/queryUnJoinCount', {
    method: 'GET',
    params: params,
  })
}

/**
 * 社区信息
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const communityInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/queryJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询社区治理
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const publicCommunityGovernance = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/queryGovernanceJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询公共服务设施
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const publicServiceInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/queryPublicJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询市政配套设施
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const municipalInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/querySupportingJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询公共活动空间
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const publicSpaceInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/queryActivityJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询特色设施
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const communityFeatureInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/querySpecialJson', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询便民服务设施
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const convenienceServiceInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/query/convenient/json', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询城市更新
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const urbanRenewalInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return request('/proposal/community/config/query/cityUpdate/json', {
    method: 'GET',
    params: {
      ...params,
      isWgs: isWgs,
    },
  })
}

/**
 * 查询城市更新
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const developmentBoundaryInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return axios.get('developmentBoundary.geojson', {
    method: 'GET',
  })
  // return request("/proposal/community/config/query/cityUpdate/json", {
  //   method: "GET",
  //   params: {
  //     ...params,
  //     isWgs: isWgs,
  //   },
  // });
}

/**
 * 查询城市更新
 *
 * @param {Object} [params={}] 参数
 *
 * @param {string} [isWgs=] 是否是wgs坐标
 */
export const buildUpAreaInformation = (
  params: object = {},
  isWgs: string = 'true'
): Promise<Response<any>> => {
  return axios.get('builtUpArea.geojson', {
    method: 'GET',
  })
  // return request("/proposal/community/config/query/cityUpdate/json", {
  //   method: "GET",
  //   params: {
  //     ...params,
  //     isWgs: isWgs,
  //   },
  // });
}

/**
 * 获取社区信息详情
 *
 * @param {string} pkid 主键id
 *
 * @param {string} communityId 社区id
 *
 */
export const queryCommunityInfoById = (
  pkid: string,
  communityId: string
): Promise<Response<CommunityInfoResp>> => {
  return request('/proposal/community/base/queryByCheckUser', {
    method: 'GET',
    params: {
      pkid,
      communityId,
    },
  })
}

/**
 * 查询审核记录
 *
 * @param {string} pkid 主键id
 *
 */
export const queryCheckedList = (
  pkid: string
): Promise<Response<Array<CheckRecordResp>>> => {
  return request('/proposal/core/apply/queryList', {
    method: 'GET',
    params: {
      resourceId: pkid,
    },
  })
}

/**
 * 添加审核记录
 *
 * @param {string} params 主键id
 *
 */
export const addApplyRecord = (params: any) => {
  return request('/proposal/core/apply/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

export const downloadCommunityConfig = (
  params: any
): Promise<AxiosResponse<Blob>> => {
  return request('/proposal/community/config/exportTotalExcel', {
    method: 'POST',
    params,
    responseType: 'blob',
  })
}

export const queryStatusTotal = (params: any): Promise<Response<any>> => {
  return request('/proposal/community/config/queryStatusTotal', {
    method: 'GET',
    params,
  })
}
